package cn.com.tom.service.impl;

import cn.com.tom.dao.BaseDao;
import cn.com.tom.service.BaseService;

import java.util.List;

public abstract class BaseServiceImpl<T> implements BaseService<T> {

    private BaseDao dao = dao();

    protected BaseDao dao() {
        String className = this.getClass().getName();
        String daoClassName = className
                .replace(".service.", ".dao.")
                .replace("ServiceImpl", "DaoImpl");
        BaseDao baseDao = null;
        try {
            baseDao = (BaseDao) Class.forName(daoClassName).newInstance();
        } catch (Exception e) {
            System.out.println("转换异常= " + e.getMessage());
        }
        return baseDao;
    }

    public boolean remove(List<Integer> ids) {
        return dao.remove(ids);
    }

    public boolean save(T bean) {
        return dao.save(bean);
    }

    public T get(Integer id) {
        return (T) dao.get(id);
    }

    public List<T> list() {
        return dao.list();
    }

    public int count() {
        return dao.count();
    }

}
